package com.boarsoft.boar.sys.biz;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.sys.SysSmsBiz;
import com.boarsoft.boar.sys.entity.SysSms;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.hibernate.biz.SimpleBizImpl;

@Component("sysSmsBiz")
public class SysSmsBizImpl extends SimpleBizImpl implements SysSmsBiz {

	@Override
	@Transactional
	public void save(SysSms sms) {
		dao.save(sms);
	}

	@Override
	@Transactional(readOnly = true)
	public PagedResult<SysSms> list(String userId, int pageNo, int pageSize) {
		StringBuffer wql = new StringBuffer();
		wql.append(" and  to='").append(userId).append("'");
		wql.append(" order by status,sendTime");

		int total = dao.getTotal(SysSms.class, wql.toString());
		List<SysSms> list = dao.list(SysSms.class, wql.toString(), pageNo, pageSize);
		return new PagedResult<SysSms>(total, list, pageNo, pageSize);
	}

	@Override
	@Transactional(readOnly = true)
	public int count(String uid) {
		StringBuffer wql = new StringBuffer();
		wql.append(" and status=0 and to='").append(uid).append("'");
		return dao.getTotal(SysSms.class, wql.toString());
	}

	@Override
	@Transactional
	public void update(String smsId) {
		StringBuffer hql = new StringBuffer();
		hql.append(" update SysSms set status=1 where id='").append(smsId).append("'");
		dao.update(hql.toString());
	}
}